<template>
  <el-card>
    <el-row
      :gutter="20"
      :class="[Wwidth > 800 ? 'show-container' : 'show-container-phone']"
    >
      <el-col :span="7">
        <el-input
          placeholder="请输入搜索内容"
          clearable
          v-model="queryForm.content"
          class="input-style"
        ></el-input>
      </el-col>

      <el-button
        type="primary"
        class="button-style"
        :icon="Search"
        @click="initGetProduct"
        >搜索</el-button
      >
      <el-button type="primary" @click="exportExcel(title)"> EXCEL </el-button>
    </el-row>

    <el-table :data="tableData" class="table-style" id="table1">
      <el-table-column
        :width="item.width"
        :prop="item.prop"
        :label="item.label"
        v-for="(item, index) in options"
        :key="index"
      >
        <template v-slot="{ row }" v-if="item.prop === 'rechargetime'">
          {{ days(row.rechargetime).format('YYYY-MM-DD HH:mm:ss') }}
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      v-model:currentPage="queryForm.pagenum"
      v-model:page-size="queryForm.pagesize"
      :page-sizes="[5, 10, 15, 20]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </el-card>
</template>

<script setup>
import { ref } from 'vue'

import { getCharge } from '../../api/payorder'
import { options } from './options'
import { Search } from '@element-plus/icons-vue'
import { exportExcel } from '@/utils/exportExcel.js'
const pagenum = ref(0)
const pagesize = ref(10)
const total = ref(0)
const queryForm = ref({})
const days = require('dayjs')
const tableData = ref([])
const title = ref('充值信息')
const Wwidth = ref()
const Wheight = ref()
// 我的电脑的浏览器窗口尺寸:宽度：1535;高度：794
const getwindow = () => {
  Wwidth.value = document.documentElement.clientWidth
  Wheight.value = document.documentElement.clientHeight
}
getwindow()

const initGetProduct = async () => {
  if (queryForm.value.content !== '') {
    const res = await getCharge(
      pagenum.value,
      pagesize.value,
      queryForm.value.content
    )
    // console.log(queryForm.value.content)
    // console.log(res.records)
    // res.records.rechargetime = days(res.records.rechargetime).format(
    //   'YYYY-MM-DD'
    // )
    console.log(res)
    total.value = res.total
    tableData.value = res.rechargeorderPage.records
  } else {
    const res = await getCharge(pagenum.value, pagesize.value)
    // console.log(queryForm.value.content)
    // res.records.rechargetime = days(res.records.rechargetime).format(
    //   'YYYY-MM-DD'
    // )
    console.log(res)
    total.value = res.total
    tableData.value = res.rechargeorderPage.records
  }

  // total.value = res.total
}
initGetProduct()
const handleSizeChange = (pageSize) => {
  pagenum.value = 1
  pagesize.value = pageSize
  initGetProduct()
}
const handleCurrentChange = (pageNum) => {
  pagenum.value = pageNum
  initGetProduct()
}
</script>

<style lang="scss" scoped>
.show-container {
  .table-style {
    width: 100%;
  }
}

.show-container-phone {
  position: relative;
  .input-style {
    width: 100px;
  }
  .button-style {
    margin-left: 40px;
    position: relative;
  }
  .table-style {
    position: absolute;
    width: 100%;
  }
}
</style>
